import { createRouter, createWebHistory } from "vue-router";
import {serveTitile} from "../api/api"
const routes = [
 
  {
    name: "downloaddetails",
    path: "/downloaddetails",
    component: () =>
      import("../view/download/componet/downloaddetails.vue"),
    meta: {
      name: "模板中心",
      breadcrumb: [
        { text: "模板中心", link: "/download" },
        { text: "详情", link: "/downloaddetails" },
      ],
    },
  },
  {
    name: "schooldetails",
    path: "/schooldetails",
    component: () =>
      import("../view/school/component/schooldetails.vue"),
    
  },
  
  {
    name: "evaluationadd",
    path: "/evaluationadd",
    component: () => import("../component/setting/home.vue"),
    meta: { name: "首页" },
  },
  {
    name: "evaluationedit",
    path: "/evaluationedit",
    component: () => import("../component/setting/edit.vue"),
    meta: { name: "首页" },
  },
  {
    name: "Home",
    path: "/home",
    redirect: "/",
    component: () => import("../view/home/home.vue"),
    children: [
      {
        name: "index",
        path: "/",
        component: () => import("../view/index/index.vue"),
        meta: { name: "首页" },
      },
      {
        name: "download",
        path: "/download",
        component: () => import("../view/download/download.vue"),
      },
      {
        name: "school",
        path: "/school",
        component: () => import("../view/school/school.vue"),
        meta: { name: "首页" },
      },
     
      
    ],
  },
 
 
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

let servetitle = ref('')
const gettitle = async ()=>{
 let res = await serveTitile({})
 servetitle.value =  res.data.title
 document.title = servetitle.value
}
gettitle()

router.beforeEach((to, from, next) => {
  // console.log('跳转前',to)
  
  if(servetitle.value==''){
    gettitle()
    next();
  }else{
    document.title = servetitle.value
    next();
  }
  
});
router.afterEach((to, from) => {
  // console.log(to,from,next,'跳转后')
});

export default router;
